home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nejlepší hry
/
Nejlepsi hry.iso
/
hry
/
plane arcade
/
planearcade.exe
/
tank3.bmp
/
input.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
2004-07-03
|
6KB
|
255 lines
#include "main.h"
//-------------------------------------------------------------
//GLOBAL
//--------------------------------------------------------------
INPUT Input;
//------------------------------------------------------------------
// Name: INPUT()
// Desc: konstruktor
//------------------------------------------------------------------
INPUT::INPUT()
{
m_pKeyboard = NULL;
m_pMouse = NULL;
m_pDirectInput = NULL;
//inicializacia poli
for (int i=0;i<256;i++)
{
KeyPRESS[i] = false;
KeyDOWN[i] = false;
}
}
//------------------------------------------------------------------
// Name: Initialize()
// Desc: inicializacia Dinput
//------------------------------------------------------------------
void INPUT::Initialize()
{
LogPrint("Nastavujem Direct Input");
//vytvori DirectInput Objekt
if(FAILED(DirectInput8Create(hIns, DIRECTINPUT_VERSION,
IID_IDirectInput8, (void**)&m_pDirectInput, NULL)))
{
LogPrint(" Nepodarilo sa vytvori¥ m_pDirectInput");
}
else
{
LogPrint(" m_pDirectInput vytvoreny");
}
//KEYBOARD =======================================================================
//Create the keyboard device object
if(FAILED(m_pDirectInput->CreateDevice(GUID_SysKeyboard, &m_pKeyboard, NULL)))
{
LogPrint(" Nepodarilo sa nastavit klavesnicu");
}
else
{
LogPrint(" Klavesnica nastavena");
}
//Set the data format for the keyboard
if(FAILED(m_pKeyboard->SetDataFormat(&c_dfDIKeyboard)))
{
LogPrint(" Nepodarilo sa nastavit format klavesnice");
}
else
{
LogPrint(" Format klavesnice nastaveny");
}
//Set the cooperative level for the keyboard
if(FAILED(m_pKeyboard->SetCooperativeLevel(hWnd,
DISCL_FOREGROUND | DISCL_NONEXCLUSIVE)))
{
LogPrint(" nepodarilo sa nastavit ccoperative level pre klavesnicu");
}
else
{
LogPrint(" cooperative level pre klavesnicu nastaveny");
}
//Acquire the keyboard
if(m_pKeyboard)
{
LogPrint(" Acquire klavesnica");
m_pKeyboard->Acquire();
}
//MOUSE =======================================================================
//Create the mouse device object
if(FAILED(m_pDirectInput->CreateDevice(GUID_SysMouse, &m_pMouse, NULL)))
{
LogPrint(" Nepodarilo sa nastavit mys ");
}
else
{
LogPrint(" Mys nastavena");
}
//Set the data format for the mouse
if(FAILED(m_pMouse->SetDataFormat(&c_dfDIMouse)))
{
LogPrint(" Nepodarilo sa nastavit formaty mysi");
}
else
{
LogPrint(" Format myse nastavena");
}
//Set the cooperative level for the mouse
if(FAILED(m_pMouse->SetCooperativeLevel(hWnd,
DISCL_FOREGROUND|DISCL_NONEXCLUSIVE)))
{
LogPrint(" nepodarilo sa nastavit ccoperative level pre mys");
}
else
{
LogPrint(" cooperative level pre mys nastaveny");
}
//Acquire the mouse
if(m_pMouse)
{
LogPrint(" Acquire mys");
m_pMouse->Acquire();
}
}
//------------------------------------------------------------------
// Name: CleanUp()
// Desc: Odstrani DInput
//------------------------------------------------------------------
void INPUT::CleanUp()
{
if(m_pKeyboard)
{
m_pKeyboard->Unacquire();
m_pKeyboard->Release();
}
if(m_pMouse)
{
m_pMouse->Unacquire();
m_pMouse->Release();
}
if(m_pDirectInput != NULL)
m_pDirectInput->Release();
}
//------------------------------------------------------------------
// Name: RefreshKeyboard()
// Desc: Ziska stlacene klavesy
//------------------------------------------------------------------
void INPUT::RefreshKeyboard()
{
int i;
//ziskanie KeyDown
m_pKeyboard->GetDeviceState(sizeof(KeyDown),
(LPVOID)&KeyDown);
//ziskanie KeyDOWN a KeyPRESS
for (i=0;i<256;i++)
{
if (KeyDOWN[i] == false)
{
KeyPRESS[i] = (KEYDOWN(KeyDown,i));
}
else
{
KeyPRESS[i] = false;
}
KeyDOWN[i] = (KEYDOWN(KeyDown,i));
}
}
//------------------------------------------------------------------
// Name: RefreshMouse()
// Desc: Ziska info o mysi
//------------------------------------------------------------------
void INPUT::RefreshMouse()
{
#define MOUSEBUTTONDOWN(key) (key & 0x80)
#define MOUSEBUTTON_LEFT 0
#define MOUSEBUTTON_RIGHT 1
#define MOUSEBUTTON_MIDDLE 2
DIMOUSESTATE MouseState;
m_pMouse->GetDeviceState(sizeof(MouseState),(LPVOID)&MouseState);
//press-reset
MouseLeftPress = 0;
MouseRightPress = 0;
//Lave tlacitko
if(MOUSEBUTTONDOWN(MouseState.rgbButtons[MOUSEBUTTON_LEFT]))
{
if (MouseLeftDown == 0)
MouseLeftPress = 1;
MouseLeftDown = 1;
}
else
{
MouseLeftDown = 0;
}
//Prave tlacitko
if(MOUSEBUTTONDOWN(MouseState.rgbButtons[MOUSEBUTTON_RIGHT]))
{
if (MouseRightDown == 0)
MouseRightPress = 1;
MouseRightDown = 1;
}
else
{
MouseRightDown = 0;
}
//solid
POINT MousePos;
ScreenToClient(hWnd,&MousePos);
GetCursorPos(&MousePos);
Mouse.X = (float) MousePos.x ;
Mouse.Y = (float) MousePos.y ;
Mouse.Z = 0.0f;
//relativne
MouseRelative.X = (float)MouseState.lX;
MouseRelative.Y = (float)MouseState.lY;
MouseRelative.Z = (float)MouseState.lZ;
}